package com.xyd.Servlet;

import com.xyd.Biz.CommodityBiz;
import com.xyd.Biz.CommonTableBiz;
import com.xyd.Biz.Impl.CommodityBizImpl;
import com.xyd.Biz.Impl.CommonTableBizImpl;
import com.xyd.Entity.Commodity;
import com.xyd.Entity.CommonTable;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/html/manage/UpdateProductServlet")
public class UpdateProductServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String commodity_id = request.getParameter("commodity_id");

        CommodityBiz commodityBiz = new CommodityBizImpl();
        CommonTableBiz commonTableBiz = new CommonTableBizImpl();
        Commodity commodity = commodityBiz.SerachCommodityById(Integer.parseInt(commodity_id));

        request.setAttribute("commodity_name",commodity.getCommodity_name());
        request.setAttribute("content",commodity.getContent());
        request.setAttribute("now_price",commodity.getNow_price());
        request.setAttribute("pic",commodity.getPic());
        request.setAttribute("original_price",commodity.getOriginal_price());
        request.setAttribute("num",commodity.getNum());
        request.setAttribute("productcolor",commodity.getProductcolor());
        request.setAttribute("productbrand",commodity.getProductbrand());
        request.setAttribute("commodity_id",commodity_id);
        request.setAttribute("common_id",commodity.getCommod_id());

        List<CommonTable> commonTableList = commonTableBiz.selTittleCommonTable();
        request.setAttribute("commonTableList",commonTableList);

        request.getRequestDispatcher("product-modify.jsp").forward(request, response);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
